<?php
require 'key.php';

$query=$_SERVER['QUERY_STRING'];
parse_str($query,$queryResult);

if($queryResult['key']===$manageKey)
{
    $data=parse_ini_file('./data.ini');
    $allUser=parse_ini_file('./user.ini');
    $allUser_Video=array();
    foreach ($data as $varName => $val)
    {
        $s=split_code($varName);
        $user=$s[0];
        $video=$s[1];
        $userName=queryKey($user,$allUser);
        if($userName!==NULL)
        {
            if($val=='1')
            {
                if(array_key_exists($userName,$allUser_Video))
                    $allUser_Video[$userName]['video'].='；'.$video;
                else
                    $allUser_Video[$userName]=['user'=>$user, 'video'=>$video];
            }
        }
    }

    foreach ($allUser_Video as $userName => $videoPair)
    {
        echo $userName.'<br>';
        $changeURL='change.php?key='.$manageKey;
        echo '<form action="'.$changeURL.'" method="post">';
        echo '<input type="text" name="video" value="'.$videoPair['video'].'"<br>';
        echo '<input type="hidden" name="user"  value="'.$videoPair['user'].'"<br>';
        echo '<input type="submit" value="变更"><br>';
        echo '</form>';
    }
    echo '变更用户机器码<br>';
    echo '<form action="'.$changeURL.'" method="post">';
    echo '用户名:';
    echo '<input type="text" name="userName" <br><br>';
    echo '新机器码:';
    echo '<input type="text" name="newUser" <br><br>';
    echo '<input type="submit" value="变更"><br>';
    echo '</form>';
}